﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CivLib.CivNum
{
  class TimeSeries : SortedList<DateTime, double>
  {
    DateTime m_start = DateTime.Now;
    TimeSpan m_timeStep = new TimeSpan(0, 15, 0);

    /// <summary>
    /// Gets array at specified index
    /// </summary>
    /// <param name="i">index of value</param>
    /// <returns>array at the index</returns>
    double this[int i]
    {
      get { return this.Values[i]; }
      set { this.Values[i] = value; }
    }
    ///// <summary>
    ///// Number of items in the series
    ///// </summary>
    //public int Count
    //{
    //  get { return this.Count(); }
    //}
    /// <summary>
    /// Get and set size of the timestep.
    /// </summary>
    public TimeSpan TimeStep
    {
      get { return m_timeStep; }
      set { m_timeStep = value; }
    }
    /// <summary>Starting time of series</summary>
    public DateTime Start
    {
      get { return m_start; }
      set { m_start = value; }
    }

    TimeSeries()
      : base()
    {
    }

    TimeSeries(TimeSeries a_timeSeries) :
      base(a_timeSeries)
    {
      m_start = a_timeSeries.Start;
      m_timeStep = a_timeSeries.TimeStep;
    }

    /// <summary>
    /// Adds the specified double[] to the end of the 
    /// </summary>
    /// <param name="a_item"></param>
    void Add(double a_item)
    {
      if (Count == 0)
      {
        this.Add(m_start, a_item);
      }
      else
      {
        this.Add(
          this.Keys[this.Keys.Count - 1].Add(m_timeStep),
          a_item);
      }
    }

    /// <summary>
    /// Add an empty array to the end of the matrix
    /// </summary>
    /// <returns>the new array added</returns>
    public double Add()
    {
      Add(new double());
      return this[Count - 1];
    }

    /// <summary>
    /// Adds a specified number of rows
    /// </summary>
    /// <param name="a_numRows"></param>
    public void Add(int a_numRows)
    {
      for (int i = 0; i < a_numRows; i++)
      {
        Add(new double());
      }
    }
  }
}
